﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TM.QWeibo.SDK.Objects;

namespace TM.QWeibo.Client.Helper
{
    public class MentionUserHelper
    {
        /// <summary>
        /// 获取我最近提及的用户
        /// </summary>
        /// <param name="count">获取条数</param>
        /// <returns></returns>
        public static List<UserInfo> GetRecent(int count = 0)
        {
            var ht = (List<UserInfo>)Common.Isolated.Get(Helper.IsolatedHelper.MentionUserKey);
            if (ht == null)
            {
                return new List<UserInfo>();
            }
            if (count > 0)
            {
                count = Math.Min(count, ht.Count);
                ht = ht.Take(count).ToList();
            }
            return ht;
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        public static void SetOne(UserInfo u)
        {
            var ht = (new List<UserInfo> { u });
            var all = GetRecent();
            if (all != null && all.Count > 0)
            {
                if (all.Any(item => string.Compare(item.Name, u.Name, StringComparison.CurrentCultureIgnoreCase) == 0))
                {
                    return;
                }
            }
            var rs = all == null ? ht : (ht.Concat(all).Take(10).ToList());
            Common.Isolated.Set(Helper.IsolatedHelper.MentionUserKey, rs);
        }
    }
}
